package com.sky.controller.admin;


import com.sky.dto.CategoryDTO;
import com.sky.dto.CategoryPageQueryDTO;
import com.sky.entity.Category;
import com.sky.result.PageResult;
import com.sky.result.Result;
import com.sky.service.CategoryService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/admin/category")
@Slf4j
public class CategoryController {
    @Autowired
    private CategoryService categoryService;

    //分类分页查询
    @GetMapping("/page")
    public Result page( CategoryPageQueryDTO categoryPageQueryDTO){

        PageResult pageResult = categoryService.page(categoryPageQueryDTO);
        return Result.success(pageResult);
    }

    //分类新增
    @PostMapping
    public Result save(@RequestBody CategoryDTO categoryDTO){

        categoryService.save(categoryDTO);

        return Result.success();
    }


    //分类修改
    @PutMapping
    public Result update(@RequestBody Category category){

        System.out.println( category);
        categoryService.update(category);

        return Result.success();
    }

    //分类删除（根据Id）
    @DeleteMapping
    public Result delete(Long id){
        categoryService.delete(id);
        return Result.success();
    }

    //分类状态（启用/禁用）
    @PostMapping("/status/{status}")
    public Result permission(@PathVariable Integer status,Long id){
        categoryService.permission(status,id);
        return Result.success();
    }

    //分类查询（根据Type）
    @GetMapping("/list")
    public Result get(Integer type){
        List categorys = categoryService.get(type);
        return Result.success(categorys);
    }



}
